#include "GMFMaterialReader.h"
#include "StringUtil.h"
#include <vector>


GMFMaterialReader::GMFMaterialReader(tstring filename):TextReader(filename)
{

}
GMFMaterialReader::~GMFMaterialReader(void)
{
}

bool GMFMaterialReader::Read()
{
	if ( !m_File)
		return false;

	tstring line;
	std::vector<tstring> result;
	if (m_File.is_open())
	{
		while (! m_File.eof() )
		{
			getline (m_File,line);
			StringUtil::Split(line,L"=",result);
			if ( result.size() == 2 ){
				m_Properties[result[0]]=result[1];
			}
			result.clear();
		}
		m_File.close();
	}
	return true;
}

bool GMFMaterialReader::HasKey(tstring key)
{
	map<tstring,tstring>::const_iterator it = m_Properties.find(key);
	return it !=  m_Properties.end();

}

tstring GMFMaterialReader::GetValue(tstring key)
{
	map<tstring,tstring>::const_iterator it = m_Properties.find(key);
	if ( it !=  m_Properties.end())
		return (*it).second;
	else
		return L"<error>";
}